﻿using AutoMapper;
using Domain.IRepositorys;
using Domain.Model;
using DTO;
using Infrastructure.UniOfWorkBase;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Application.App
{
    public class TaskCategoryApplication
    {
        //public IEFUnitOfWork efUnitOfWork { get; set; }
        public IUserRepository userRepository { get; set; }
        public ITaskCategoryRepository taskCategoryRepository { get; set; }
        public ITaskRepository taskRepository { get; set; }
        public ITaskTakeRepository taskTakeRepository { get; set; }
        public IBlackListRepository blackListRepository { get; set; }
        public IWalletRepository walletRepository { get; set; }

        public ILogger<TaskCategoryApplication> Logger { get; set; }
        public IList<TaskCategoryOutput> GetTaskCategorys(int uid)
        {
            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap<TaskCategoryAggregate, TaskCategoryOutput>();

                cfg.SourceMemberNamingConvention = new PascalCaseNamingConvention();
                cfg.DestinationMemberNamingConvention = new LowerUnderscoreNamingConvention();
            });
            var mapper = config.CreateMapper();

            var list= taskCategoryRepository.Entities.Where(i=>!i.IsDelete&&i.IsEnable).ToList();

            var rlist = mapper.Map<IList<TaskCategoryOutput>>(list);
            

            return rlist;
        }

        public IList<TaskCategorySimpleOutput> GetTaskCategoryTabs(int uid)
        {
            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap<TaskCategoryAggregate, TaskCategorySimpleOutput>();

                cfg.SourceMemberNamingConvention = new PascalCaseNamingConvention();
                cfg.DestinationMemberNamingConvention = new LowerUnderscoreNamingConvention();
            });
            var mapper = config.CreateMapper();

            var list = taskCategoryRepository.Entities.Where(i => !i.IsDelete && i.IsEnable).ToList();

            var rlist = mapper.Map<IList<TaskCategorySimpleOutput>>(list);

            rlist.Insert(0, new TaskCategorySimpleOutput() {
                Icon="",
                ID=0,
                Title="全部"
            });

            return rlist;
        }

        public TaskCategoryOutput GetTaskCategoryByID(int v, int id)
        {
            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap<TaskCategoryAggregate, TaskCategoryOutput>();

                cfg.SourceMemberNamingConvention = new PascalCaseNamingConvention();
                cfg.DestinationMemberNamingConvention = new LowerUnderscoreNamingConvention();
            });
            var mapper = config.CreateMapper();

            var f = taskCategoryRepository.Entities.FirstOrDefault(i => i.ID ==id);


            return mapper.Map<TaskCategoryOutput>(f);
        }
    }
}
